package com.yx.utils;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 86159
 */
public class BeanCopyUtils {
    private BeanCopyUtils(){}
    public static <V> V copyBean(Object source,Class<V> clazz){
        //创建目标对象
        V result=null;
        try {
            result=clazz.newInstance();
            BeanUtils.copyProperties(source, result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //实现属性copy

        //返回结果。
        return result;
    }
    public static <V> List<V> copyBeanList(List<? extends Object> list, Class<V> clazz){
        return list.stream().map(o -> copyBean(o, clazz)).collect(Collectors.toList());
    }
}
